package com.lisp.algorithm.leetcode;

import java.util.ArrayList;
import java.util.List;

public class Path {

	public static void main(String[] args) {
		Node_ root = new Node_(0, new Node_[] {});
	}
	
	public static List<Node_> path(Node_ n, Node_ target) {
		if(n == target) {
			ArrayList<Node_> ret = new ArrayList<>();
			ret.add(target);
			return ret;
		} 
		
		if(n.children == null) {
			return null;
		}
		
		for(Node_ c : n.children) {
			List<Node_> path = path(c, target);
			if(path != null) {
				path.add(0, n);
				return path;
			}
		}
		
		return null;
	}
	
	static class Node_ {
		int value;
		Node_[] children;
		
		public Node_(int value, Node_[] children) {
			super();
			this.value = value;
			this.children = children;
		}
	}
}
